//
//  SLChangeNotifyVC.m
//  SlockApp
//
//  Created by 凯朱 on 2024/7/30.
//

#import "SLChangeNotifyVC.h"
#import "SLVerifyCodeVC.h"
@interface SLChangeNotifyVC ()

@end

@implementation SLChangeNotifyVC
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpSubViews];
}

-(void)setUpSubViews{
    self.title = kLocalString(@"Change notification Email");
   
    _sureBtn.btnStyle = 1;
    [_sureBtn setTitle:kLocalString(@"Send verification code") forState:UIControlStateNormal];
    self.bgView1.layer.cornerRadius = 20;
    self.bgView1.layer.masksToBounds = YES;
    self.bgView2.layer.cornerRadius = 20;
    self.bgView2.layer.masksToBounds = YES;
    _tf1.text = kReplace(kCurClickDevice.pushEmail, kUserInfo.email);
    _tf1.userInteractionEnabled = NO;
    
    _tipLbl1.text = kLocalString(@"Current notification Email");
    _tipLbl2.text = kLocalString(@"New notification Email");
    [_tf1 setPlaceholderWithPlaceholderText:kLocalString(@"Current notification Email") withColor:KColor_placeholdar withFont:kFont(16)];
    [_tf2 setPlaceholderWithPlaceholderText:kLocalString(@"New notification Email") withColor:KColor_placeholdar withFont:kFont(16)];
    [_tf1 showCloseBtn];
    [_tf2 showCloseBtn];
}

- (IBAction)sureAction:(id)sender {
    if (![_tf2.text isValidEmail]) {
        kShowToast(@"Please enter a email");
        return;
    }
    [self sendCode:3];
}

-(void)sendCode:(NSInteger)style{
    kWeakSelf(self);
    [ZCTool showLoadingOnKeyWindow];
    NSString *url = [NSString stringWithFormat:@"/msl_user/sendMail/%@",_tf2.text];
    [ZKHttpManager postWithPath:url params:nil finished:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull code, NSString * _Nonnull message) {
        [ZCTool hideLoadingOnKeyWindow];
        BOOL isHaveSend = [code isEqualToString:@"500"];
        kShowToast(message);
        if (!isSuccessed && !isHaveSend) {
            return;
        }
        [weakself.tf2 endEditing:YES];
        SLVerifyCodeVC *vc = [[SLVerifyCodeVC alloc] init];
        vc.style = 3;
        vc.pushEmail = weakself.tf2.text;
        vc.changeEmailBlock = weakself.changeEmailBlock;
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

@end
